﻿<?php
	Class all_model extends CI_Model{
		public function __construct(){
			parent::__construct();
		}
		public function listAllBlogs(){
			$this->db->select('data.id,data.title,data.text,employee.ename,company.name')
						->from('data')
						->join('employee','data.editby = employee.id')
						->join('company','data.company = company.id');
			$query = $this->db->get();
			return $query->result();
		}
		/* $DATA = ARRAY */
		public function createNewBlog($data){
			$return = array();
			$this->db->select('id');
			$emp = $this->db->get_where('employee',array('id'=>1));
			$empArray = $emp->result_array();
			$eid = $empArray[0]['id'];
			
			$this->db->select('id');
			$comp = $this->db->get_where('company',array('id'=>1));
			$compArray = $emp->result_array();
			$cid = $compArray[0]['id'];
			
			$params = array(
				'title'=>$data['title'],
				'text'=>$data['blog'],
				'editby'=>$eid,
				'company'=>$cid,
			);
			$this->db->insert('data',$params);
			if($this->db->affected_rows()>0){
				return true;
			}else{
				return false;
			}
		}
		public function showEmployee($id){
			$this->query = $this->db->get_where('employee',array('id'=>$id));
			$this->result = $query->result();
			return json_encode($this->result);
		}
		public function listAllEmployees(){
			$this->db->select('employee.id , employee.ename,employee.address,employee.email,employee.status,company.name')
						->from('employee')
						->join('company','company.id = employee.company');
			$query = $this->db->get();
			
			return $query->result();
		}
	}
?>